import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shoes_shop/pages/index_page.dart';
import 'package:shoes_shop/pages/userInfo/addressList/address_list_provider.dart';

import 'api/api.dart';
import 'models/public_provider_model.dart';

void main() async {
  runApp(MyApp());
  init(); //云开发初始化
  configLoading();//easyloading 自定义 初始化
}

void configLoading() {
  EasyLoading.instance
    ..indicatorType = EasyLoadingIndicatorType.ring;
}

class MyApp extends StatelessWidget with WidgetsBindingObserver {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    print('=====MyApp');
    //引入provider
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_)=> PublicProviderModel()),
        ChangeNotifierProvider(create: (_) => AddressListProvider()),
      ],
      child: ScreenUtilInit( //ScreenUtil初始化
        designSize: Size(750, 1334),
        builder: () => RefreshConfiguration(
          headerTriggerDistance: 60.0,
          maxUnderScrollExtent:30,
          child: MaterialApp(
            title: 'shose shop',
            debugShowCheckedModeBanner: false,
            theme: ThemeData(
              primarySwatch: Colors.blue,
              textTheme: GoogleFonts.latoTextTheme(
                Theme.of(context).textTheme,
              ),
              visualDensity: VisualDensity.adaptivePlatformDensity,
            ),
            home: IndexPage(),
            builder: EasyLoading.init(),//easyloading 初始化
          ),
        ),
      ),
    );
  }
}
